package com.gxa.controller.ly.roleManagement;


import com.gxa.common.R;
import com.gxa.entity.SysRole;
import com.gxa.service.RoleManagementService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Api(value = "角色管理",tags = "角色管理接口API")
@Controller
@RequiresRoles(value = {"超级管理员","院长"},logical = Logical.OR)
@RequestMapping("/systemManagement/roleCompany")
public class RoleManagementController {

    @Autowired
    RoleManagementService roleManagementService;
    /**
     * 查找角色接口
     * @param currentPage 当前页
     * @param pageSize 每页条数
     * @return JSON
     */
    @RequestMapping(value = "/findRoleList",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查找所有角色接口",notes = "查找所有角色",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页数", paramType = "query", dataType = "String", required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findRoleList(@RequestParam("currentPage") Integer currentPage,@RequestParam("pageSize") Integer pageSize) {

        return roleManagementService.findRoleList(currentPage,pageSize);
    }


    /**
     * 添加角色接口
     * @param sysRole 菜单对象
     * @return 影响行数
     */
    @RequestMapping(value = "/addRole",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加角色接口",notes = "添加角色",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addRole(@RequestBody @ApiParam(name = "sysRole",value = "角色对象",required = true) SysRole sysRole) {

        return roleManagementService.addCRole(sysRole);
    }

    /**
     * 删除角色
     * @param id 菜单id
     * @return 影响行数或失败
     */
    @RequestMapping(value = "/delRole",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除角色接口",notes = "删除角色",httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "id", value = "角色id", paramType = "query", dataType = "String", required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R delRole(Integer id) {

        return roleManagementService.delRole(id);
    }

    /**
     * 更新角色接口
     * @param sysRole 需要修改的对象
     * @return 返回是否成功
     */
    @RequestMapping(value = "/updateMenu",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "更新角色接口",notes = "更新角色",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateMenu(@RequestBody  @ApiParam(name = "SysRole",value = "角色对象",required = true) SysRole sysRole) {

        return roleManagementService.updateMenu(sysRole);
    }

    /**
     * 根据name查角色
     * @param name 角色名称
     * @return
     */
    @RequestMapping(value = "/findRoleByName",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据名字查角色接口",notes = "根据名字查角色",httpMethod = "GET", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页数", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "name", value = "角色名字", paramType = "query", dataType = "String", required = true),
    })
    public R findRoleByName(@RequestParam("name") String name,Integer currentPage,Integer pageSize){
        return roleManagementService.findRoleByName(name,currentPage,pageSize);
    }


    @RequestMapping(value = "/findMenuListByRoleId",method = RequestMethod.GET)
    @ResponseBody
    public R findMenuListByRoleId(@RequestParam("id")Integer id){
        //测试一下能不能push
        return roleManagementService.findMenuListByRoleId(id);
    }
}
